let request = require('../../../../utils/request.js')

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    markerPark: Object,
    shopId: String
  },

  /**
   * 组件的初始数据
   */
  data: {
    setedParkTicket: ''
  },

  lifetimes: {
    attached: function() {
      console.log('在组件实例进入页面节点树时执行')
      
      //  获取停车场已配置停车券
      this.getParkTicket()
    },
    detached: function() {
      console.log('在组件实例被从页面节点树移除时执行')
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
      /**
     * 跳转到配置停车券页面
     */
    toSetParkTicket() {
      var _this = this;
      request.http(
        '/shop/shop-park-ticket/get-by-shop-id', 
        'GET', 
        {shopId: this.data.shopId}
      ).then(res => {
        console.log('可配置停车券：', res.data.data)
        if(res.data.data.length > 0){
          wx.navigateTo({ url: '/pages/park-ticket/set-patk-ticket/setPatkTicket?parkId=' + this.data.markerPark.id })
        } else {
          wx.showModal({
            title: '暂无可配置引流卷',
            content: '点击确定查看获取方式',
            success (res) {
              if (res.confirm) {
                _this.triggerEvent('modify')
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
        }
      })
    },
    /**
     * 获取停车场已配置停车券
     */
    getParkTicket() {
      request.http(
        '/shop/park-ticket-set/get-by-park-id', 
        'GET', 
        {parkId: this.data.markerPark.id}
      ).then(res => {
        let setedParkTicket = ''
        res.data.data.forEach((parkTicket)=> {
          setedParkTicket += parkTicket.parkingDuration + '小时券' + '（' + parkTicket.remainingQuantity + '张）；'
        })
        this.setData({ setedParkTicket: setedParkTicket })
      })
    }
  }
})
